#include <iostream>
#include <queue>
using namespace std;
const int N=1e5+10;
int vis[N*2];
int main()
{
	int n,k;
	cin>>n>>k;
	
	queue<pair<int,int>> q;
	vis[n]=1;
	q.push({n,0});
	int ret=0;
	while(q.size())
	{

		int x=q.front().first;
		int step=q.front().second;
		if(x==k)
		{
			ret=step;
			break;
		}
		
		q.pop();
		if(x-1>=0 && !vis[x-1])
		{
			vis[x-1]=1;
			q.push({x-1,step+1});
		}
		if(x+1<=k && !vis[x+1])
		{
			vis[x+1]=1;
			q.push({x+1,step+1});
		}
		if(x*2<=2*k && !vis[x*2])
		{
			vis[x*2]=1;
			q.push({x*2,step+1});
		}
	}
	
	cout<<ret<<endl;
	return 0;
}
